package com.repair.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.repair.entity.ForumPost;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface ForumPostMapper extends BaseMapper<ForumPost> {
    
    @Select("SELECT fp.*, u.username as username " +
            "FROM forum_post fp " +
            "LEFT JOIN user u ON fp.user_id = u.id " +
            "WHERE fp.status = 1 " +
            "ORDER BY fp.create_time DESC " +
            "LIMIT #{offset}, #{limit}")
    List<ForumPost> getPostList(@Param("offset") int offset, @Param("limit") int limit);
    
    @Select("SELECT COUNT(*) FROM forum_post WHERE status = 1")
    int getPostCount();

    @Select("SELECT fp.*, u.username, u.real_name " +
            "FROM forum_post fp " +
            "LEFT JOIN user u ON fp.user_id = u.id " +
            "WHERE fp.id = #{id}")
    ForumPost getPostById(@Param("id") Long id);
} 